///*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package Supporter;
//
//import java.io.InputStream;
//import java.util.Vector;
//import javax.microedition.media.Manager;
//import javax.microedition.media.Player;
//
///**
// *
// * @author Van persie
// */
//public class SoundSupporter {
//    Vector soundSource = null;
//    public SoundSupporter()
//    {
//        soundSource = new Vector();
//    }
//    
//    public Player getSound(String pathFile)
//    {
//        
//        InputStream inStr = getClass().getResourceAsStream(pathFile);
//        Player temp = null;
//        try{
//             temp = Manager.createPlayer(inStr, "audio/X-wav");
//        }catch(Exception e) {}
//        return temp;
//        
//    }
//}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Supporter;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;

/**
 *
 * @author Van persie
 */
public class SoundSupporter implements PlayerListener {

    Vector soundSource = null;
    public Player player = null;

    public SoundSupporter() {
        soundSource = new Vector();
    }

    public Player getSound(String pathFile, int type) throws IOException {

        InputStream inStr = this.getClass().getResourceAsStream(pathFile);
        player = null;
        //player.addPlayerListener(this);
        try {
            if (type == 1) {
                player = Manager.createPlayer(inStr, "audio/X-wav");
                player.setLoopCount(1);
            } else {
                player = Manager.createPlayer(inStr, "audio/midi");
                player.setLoopCount(1);
            }

            player.prefetch();
        } catch (Exception e) {
        }
        return player;
    }

    public void playsound() throws MediaException {

        player.stop();
        player.setLoopCount(1);
        player.start();
    }


    public Player getplayer() {
        return player;
    }

    public void stopsound() throws MediaException {

        player.stop();
    }

    public void playerUpdate(Player player, String event, Object eventData) {
        
    }
}
